/*
 * MVCME framework (www.radoslaw.biz/mvcme)
 * This framework is an attempt of creating MVC pattern for Java ME.
 * Feel free to change and distribute code and binaries of this project.
 * Should you want to provide any feedback, contact me at kowalski@radoslaw.biz
 */

package biz.radoslaw.mvcme;

import biz.radoslaw.mvcme.view.View;
import java.util.Stack;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public abstract class MvcMIDlet extends MIDlet implements CommandListener, MIDletController {

    private Display display;     // The display for this MIDlet
    private Stack currentViews;

    public MvcMIDlet() {
        display = Display.getDisplay(this);
        currentViews = new Stack();
    }

    public abstract void startApp();

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable s) {
        throw new UnsupportedOperationException();
    }

    public void show(View view) {
        this.currentViews.push(view);
        view.getDisplayable();
        view.refresh();
        display.setCurrent(view.getDisplayable());
    }

    public void close() {
        this.currentViews.pop();
        View v = (View)(this.currentViews.peek());
        v.getDisplayable();
        v.refresh();
        display.setCurrent(v.getDisplayable());
    }

}
